{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "384fa4a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\ndeque优点\\n1.有序结构的优点\\n2.数据存取方式——队首尾都可以进行存读\\n3.数据修改方式——队首尾都可以进行修改\\n\\n4.deque两队都可以发生——增，删，查\\n\\ndeque缺点：\\n1.同queue\\n\\ndeque应用\\n1.广度优先搜索\\n2.滑动窗口算法\\n3.缓存实现\\n'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "deque优点\n",
    "1.有序结构的优点\n",
    "2.数据存取方式——队首尾都可以进行存读\n",
    "3.数据修改方式——队首尾都可以进行修改\n",
    "\n",
    "4.deque两队都可以发生——增，删，查\n",
    "\n",
    "deque缺点：\n",
    "1.同queue\n",
    "\n",
    "deque应用\n",
    "1.广度优先搜索\n",
    "2.滑动窗口算法 【一端增，一端减】\n",
    "3.缓存实现\n",
    "4.回文检验【deque两端同时出】\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "068b723c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Deque:\n",
    "    def __init__(self):\n",
    "        self.items = []          # 初始化，以list为基础构建queue\n",
    "    def isEmpty(self):\n",
    "        return self.items == []  # 判断queue是否为空\n",
    "    def addFront(self,item):\n",
    "        self.items.insert(item) # 入队——在queue队首添加元素\n",
    "    def removeFront(self):\n",
    "        return self.items.pop(0) # 出队——在queue队首删除元素，并返回它 ≈ 读队首\n",
    "    \n",
    "    def addRear(self,item):\n",
    "        self.items.insert(0,item) # 入队——在queue队尾添加元素\n",
    "    def removeRear(self):\n",
    "        return self.items.pop() # 出队——在queue队尾删除元素，并返回它 ≈ 读队首\n",
    "    \n",
    "    def GetFront(self):            # 读取队首\n",
    "        return self.items[0]\n",
    "    def GetRear(self):            # 读取队尾\n",
    "        return self.items[len(sele.items)-1]\n",
    "    def size(self):\n",
    "        return len(self.items)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
